<template>
  <el-aside :width="isCollapse?'64px':'200px'">
    <el-menu router :collapse-transition="false" :collapse="isCollapse" unique-opened :default-active="$route.path" class="el-menu-vertical-demo" background-color="#313743" text-color="#fff" active-text-color="#319cfe">
      <div @click="chageCollapse" class="collapse">
        <i :class="ico"></i>
      </div>
      <!-- 一级菜单 -->
      <el-submenu v-for="item,idx in menuList" :key="item.id" :index="item.path">
        <!-- 菜单模板区 -->
        <template slot="title">
          <i :class="'iconfont '+iconList[idx]"></i>
          <span>{{item.authName}}</span>
        </template>
        <!-- 二级菜单 -->
        <el-menu-item v-for="children in item.children" :key="children.id+''" :index="'/home/'+children.path">
          <i class="el-icon-menu"></i>
          <span>{{children.authName}}</span>
        </el-menu-item>
      </el-submenu>

    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: 'asideList',
  props: {
    menuList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      iconList: ['icon-users', 'icon-tijikongjian', 'icon-shangpin', 'icon-danju', 'icon-baobiao'],
      // 是否折叠
      isCollapse: false,
      // 收回按钮显示的图标
      ico: 'el-icon-caret-right'
    }
  },
  methods: {
    chageCollapse() {
      if (this.isCollapse) {
        this.ico = 'el-icon-caret-right'
      } else {
        this.ico = 'el-icon-caret-left'
        this.asideWidth = 'auto'
      }
      this.isCollapse = !this.isCollapse
    }
  }
}
</script >

<style lang="less" scoped>
.el-aside {
  transition: all 0.3s;
}
.el-menu {
  border-right: 0;
}
.iconfont {
  margin-right: 10px;
}
.collapse {
  position: relative;
  width: 100%;
  height: 56px;
  text-align: center;
  line-height: 56px;

  font-size: 25px;

  .el-icon-caret-left {
    color: #909399;
    transform-origin: center;
    transition: all 0.3s;
  }
  .el-icon-caret-right {
    position: absolute;
    top: 15px;
    right: 14px;
    color: #909399;
    transform-origin: center;
    transition: all 0.3s;
  }
  &:hover {
    color: #319cfe;
    cursor: pointer;
    background-color: #272c36;

    .el-icon-caret-left {
      color: white;
      transform: rotate(180deg);
    }
    .el-icon-caret-right {
      color: white;
      transform: rotate(-180deg);
    }
  }
}
</style>
